﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SharpSoft.Web
{
    /// <summary>
    /// 权限定义
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
    public class AuthorizeAttribute : Microsoft.AspNetCore.Authorization.AuthorizeAttribute
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="needCheckPermission">是否需要检查权限定义为true则会在用户访问此Authorize定义的对象时检查其权限</param>
        public AuthorizeAttribute(bool needCheckPermission = false)
        {
            this.CheckPermission = needCheckPermission;

        }

        public const string PermissionCheckPolicyName = "PermissionCheck";



        private bool _CheckPermission;

        /// <summary>
        /// 是否需要检查用户|角色的特定权限
        /// </summary> 
        public bool CheckPermission
        {
            get { return _CheckPermission; }
            set
            {
                _CheckPermission = value;

                if (value)
                {
                    this.Policy = PermissionCheckPolicyName;
                }
            }
        }


    }
}
